<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Bistro extends Authenticatable implements JWTSubject
{
    use Notifiable;
    //
    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $table = 'bistros';

    protected $fillable = [
        'head_store_id', 'name', 'qr_code', 'start_fee', 'address', 'area', 'password', 'account'
    ];

    public function scopeName($query, $name) {
        if(!empty($name)) {
            return $query->where('name', 'like', '%'.$name.'%');
        }
        return $query;
    }

    public function scopeHeadStoreId($query, $head_store_id) {
        if(!empty($head_store_id)) {
            return $query->where('head_store_id', $head_store_id);
        }
        return $query;
    }

    public function headStore() {
        return $this->belongsTo('\App\Model\HeadStore');
    }

    public function product() {
        return $this->hasMany('\App\Model\Product');
    }

//    public function scopeName($query, $name) {
//        if(!empty($name)) {
//            return $query->where('name', 'like', '%'.$name.'%');
//        }
//        return $query;
//    }

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        // TODO: Implement getJWTIdentifier() method.
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        // TODO: Implement getJWTCustomClaims() method.
        return [];
    }
}
